﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZhiAo.CoreLibrary.Common
{
    public class SQLParamConvert
    {
        public static string Convert(string sql)
        {
            sql = sql.Replace("#USER_ID#", UserInfo.UserId);
            sql = sql.Replace("#USER_LAN#", UserInfo.Language);
            sql = sql.Replace("#USER_NAME#", UserInfo.UserName);
            sql = sql.Replace("#LOGIN_NO#", UserInfo.LoginNo);
            sql = sql.Replace("#DEPT_ID#", UserInfo.OperSide);
            sql = sql.Replace("#DEPT_NAME#", UserInfo.OperSideName);
            sql = sql.Replace("#COMPANY_ID#", UserInfo.CompanyCode);
            sql = sql.Replace("#COMPANY_NAME#", UserInfo.CompanyCode);
            sql = sql.Replace("#ROLE_ID#", UserInfo.RoleId);
            sql = sql.Replace("#ROLE_NAME#", UserInfo.RoleName);

            //循环处理SQL中变量
            List<string> listParam = ZhiAo.CoreLibrary.Common.DynamicParam.GetParam(sql, "{", "}");
            foreach (string param in listParam)
            {
                sql = sql.Replace("{" + param + "}", ZhiAo.CoreLibrary.Common.PageHelper.Request(param));
            }

            return sql;
        }
    }
}
